package cn.drew.house.controller;

import cn.drew.basic.utils.AjaxResult;

import cn.drew.basic.utils.PageList;
import cn.drew.house.domain.RentingInformation;
import cn.drew.house.query.RentingInformationQuery;
import cn.drew.house.service.RentingInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/renting")
public class RentingInformationController {

    @Autowired
    private RentingInformationService rentingInformationService;

    @GetMapping
    public List<RentingInformation> findALl(){
        List<RentingInformation> list = rentingInformationService.findAll();
        return list;
    }

    @GetMapping("/{id}")
    public RentingInformation findById(@PathVariable("id") Long id){
        RentingInformation RentingInformation = rentingInformationService.findById(id);
        return RentingInformation;
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody RentingInformation RentingInformation){
        if(RentingInformation.getRtId() != null){
            rentingInformationService.update(RentingInformation);
        }else{
            rentingInformationService.add(RentingInformation);
        }

        return AjaxResult.success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult Delete(@PathVariable("id") Long id){
        rentingInformationService.delete(id);
        System.out.println(id);
        return AjaxResult.success();
    }

//    分页查询
    @PostMapping
    public PageList<RentingInformation> queryByPage(@RequestBody RentingInformationQuery RentingInformationQuery){
        PageList<RentingInformation> pageList = rentingInformationService.queryByPage(RentingInformationQuery);
        return pageList;
    }

    //批量删除
    @PatchMapping
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        rentingInformationService.patchDelete(ids);
        return AjaxResult.success();
    }
    
//    //无线级数
//    @GetMapping("/tree")
//    public List<RentingInformation> tree(){
//        List<RentingInformation> tree = rentingInformationService.tree();
//        System.out.println(tree);
//        return rentingInformationService.tree();
//
//    }


    
}
